#include "mainwindow.h"
#include "ndb.h"
#include <QApplication>
#include <QStyleFactory>
#include <QSharedMemory>
#include "taskitem.h"
#include "configfile.h"
#include <QScreen>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
#ifdef QT_NO_DEBUG
    QSharedMemory shared("transaction_manager");
    if (!shared.create(1))  // 共享内存被占用则直接返回
    {
        QMessageBox::information(nullptr,"提示","程序已经运行！","确定");
        app.quit();
        return 0;
    }
#endif


#if(QT_VERSION >= QT_VERSION_CHECK(5,6,0))
        QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif


        // 设置Qt字体支持4k屏
        const double DEFAULT_DPI = 96.0;
        double dpiX  = QApplication::primaryScreen()->logicalDotsPerInch();
        float fontSize = dpiX / DEFAULT_DPI;
        QFont font = app.font();
        font.setFamily(QStringLiteral("宋体"));
        font.setPointSize(font.pointSize()*fontSize);
        app.setFont(font);


    taskItem::configfile = new configFile;
    taskItem::config = &taskItem::configfile->m_config;

    Ndb ndb("data.db");
    MainWindow w;

    w.m_config = taskItem::config;



    QObject::connect(&ndb, &Ndb::DataBaseOpenError, &w, &MainWindow::DataBaseOpenError);
    QObject::connect(&w, &MainWindow::ApplicationQuit, &app, &QApplication::quit);
    w.loadTaskItem();
    w.showData();
    w.show();
    return app.exec();
}
